Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace repeated messages instead of appending more #55

Merged
merged 1 commit into from
Mar 22, 2024
Merged

Conversation

skatkov
Copy link
Contributor

@skatkov skatkov commented Mar 20, 2024

Two bug fixes in one!

Double definition bug

pb.messages "This is the first string of the repeating ones"
pb.messages "This is the second one"

This code right now equals to this:

pb.messages ["This is the first string of the repeating ones", "This is the second one"]

But jbuilder handles this case differently. So in this PR behaviour is change to one similar to jbuilder - only last definition will be persisted and first one will be discarded.

pb.messages ["This is the second one"]

Double render bug

It seems that rails-twirp gem does double rendering and we're having fields with duplicated values. e.g.

pb.redemption_methods [:instore, :online]

could end up with as [:instore, :online, :instore, :online]

@skatkov skatkov requested a review from julik March 20, 2024 18:23
Copy link
Contributor

@julik julik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not entirely clear what the desired behavior is here - and this needs a test

lib/pbbuilder.rb Outdated Show resolved Hide resolved
lib/pbbuilder.rb Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@skatkov skatkov changed the title Replace enum messages, don't concut them Replace enum messages, don't append them Mar 20, 2024
@skatkov skatkov requested a review from julik March 20, 2024 18:57
Copy link
Contributor

@julik julik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

GTG let's just make the wording in the tests a bit nicer pls

test/pbbuilder_test.rb Outdated Show resolved Hide resolved
test/pbbuilder_test.rb Outdated Show resolved Hide resolved
@skatkov skatkov force-pushed the fix-enums branch 2 times, most recently from 2210e6f to 61fa3eb Compare March 22, 2024 09:17
adjust comments

adding a test

fixing dupplicated fields

replace Array.wrap with simpler form

update changelog
@skatkov skatkov requested a review from julik March 22, 2024 09:21
@julik julik changed the title Replace enum messages, don't append them Replace repeated messages instead of appending more Mar 22, 2024
@skatkov skatkov merged commit 253cdcb into main Mar 22, 2024
8 checks passed
@skatkov skatkov deleted the fix-enums branch March 22, 2024 11:27
julik pushed a commit that referenced this pull request Mar 22, 2024
This is a breaking change. Previously, we would handle repeated fields
as something you can call multiple times on the builder, like so:

```
pb.messages "This is the first string of the repeating ones"
pb.messages "This is the second one"
```

From now, this is no longer going to work and you need to assign all the messages
in one go:

`pb.messages ["This is the first string of the repeating ones", "This is the second one"] `

This behaviour is in alignment with how `jbuilder` handles this. The last assignment wins, the
previous one will be discarded.

`pb.messages ["This is the second one"]`

It seems that rails-twirp gem does double rendering sometimes and some fields have duplicated values. e.g.

`pb.redemption_methods [:instore, :online]`

could end up in putput as `[:instore, :online, :instore, :online]`

That bug we are going to fix as well, but for now making repeated fields safer
is a good first step.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants